package 我的Java学习_算法基础.day_03;

import java.util.Random;

import static 我的Java学习_算法基础.day_01.唯一成对的数.printArray;

public class _038_题解_调整数组顺序_奇数在左偶数在右 {
    public static void main(String[] args) {
        int[] array = new int[10];
        Random random = new Random();
        for (int i = 0 ;i<array.length;i++){
            array[i]= random.nextInt(20);
        }
        printArray(array);
        change(array,0,array.length-1);
        printArray(array);
    }
    private static void change(int[] array,int begin,int end){
        int left = begin,right = end;
        while(left<=right){
            while(left<=right&&array[left]%2!=0) {
                left++;
            }
            while(left<=right&&array[right]%2==0){
                right--;
            }
            if(left<right){
                int x = array[left];
                array[left] = array[right];
                array[right] = x;

            }
        }
    }
}
